package com.newtouch.bxzs.database.synchronize.mapper.income;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.newtouch.bxzs.common.base.model.IncomeDetail;
import com.newtouch.bxzs.database.synchronize.model.income.IncomeDetailVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

/**
 * 收入详情Mapper
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/8 13:08</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Mapper
public interface IncomeDetailMapper extends BaseMapper<IncomeDetail> {

    /**
     * 批量添加收入详情数据
     * @param incomeDetails
     * @param createTime
     * @return
     */
    @Insert({"<script>insert into ASSISTANT_INCOME_DETAIL(INCOME_DETAIL_ID,CREATE_USER_ID,CREATE_TIME," +
            "MONTH,POLICY_NUMBER,POLICY_HOLDER_NAME,INSUREDER_NAME,POLICY_EFFICIENT_DATE," +
            "PRODUCT_CODE,PRODUCT_NAME,INCOME_PRE_TAX,DATA_SOURCE,POLICY_EXPIRATION_DATE,USER_JOB_NUMBER) values" +
            "<foreach collection='list' item='item' separator=',' >" +
            "(REPLACE(uuid(),'-','')," +
            "'admin',#{createTime}," +
            "#{item.month},#{item.policyNumber}," +
            "#{item.policyHolderName},#{item.insurederName},#{item.policyEfficientDate}," +
            "#{item.productCode},#{item.productName},#{item.incomePreTax}," +
            "#{item.dataSource},#{item.policyExpirationDate},#{item.userJobNumber})" +
            "</foreach>" +
            "ON DUPLICATE KEY UPDATE" +
            " UPDATE_USER_ID = values(CREATE_USER_ID)</script>"})
    int addIncomeDetailList(@Param("list")List<IncomeDetailVO> incomeDetails,@Param("createTime") Date createTime);
}
